function extend(parent_class, child_class)
    local tbl = {}
    local mt = getmetatable(parent_class)
    if mt ~= nil then
        tbl.__tostring = mt.__tostring
        tbl.__call = mt.__call
    end
    child_class.__index = parent_class
    setmetatable(child_class,child_class)
    return child_class
end


--[[句柄管理器]]

handle_manager_class = {

    create = function ()
        local object = {
            top     = 1,
            stack   = {},
            map     = {},
            id_table= {},
            __index = handle_manager_class
        }
        object.top = 1
        object.stack = {}
        object.map = {}
        object.id_table = {}
        setmetatable(object,object)
        return object
    end,

    destroy = function (self)

    end,

    allocate = function (self)
        local id = self.top
        local stack = self.stack
        if #stack == 0 then
            id = self.top
            self.top = self.top + 1
        else
            id = stack[#stack]
            table.remove(stack,#stack)
            self.map[id] = nil
        end
        self.id_table[id] = 1
        return id
    end,

    free = function (self,id)
        if self.id_table[id] == nil and self.map[id] ~= nil then
            print('重复回收',id)
        elseif self.id_table[id] == nil then
            print('非法回收',id)
        end
        if self.map[id] == nil and self.id_table[id] ~= nil then
            self.map[id] = 1
            self.id_table[id] = nil
            table.insert(self.stack,id)
        end
    end,
}
